import java.util.Arrays;
import java.util.Random;
/*
找3个数
有一组已经排好顺序的数据：5,13,19,21,37,56,64,75,80,88,92。编写代码
查询数组中是否包含数据78
使用二分查找法

a b c d e f
0         5
(minPos + maxPos)/2

a b c d e
0       4
(minPos + maxPos)/2

... 10 11 12
... 20  21  22

a b c d e

 */
class Z1erfen{
    public static void main(String[] args) {
        //目标数组
        int[] arr = {5,13,19,21,37,56,64,75,80,88,92};
        //目标
        int target = 78;
        //查找
        int leftPos = 0;
        int rightPos = arr.length-1;
        while (true){
            //寻找中点
            int midPos = (leftPos+rightPos)/2;
            if(arr[midPos]==target){
                //找到了
                System.out.println("包含"+target+",下标为："+midPos);
                break;
            }else if(target>arr[midPos]){
                //目标更大，在右侧
                leftPos = midPos+1;
            }else {
                //目标更小，在左侧
                rightPos = midPos-1;
            }
            //找不到
            if(leftPos>rightPos){
                System.out.println("没有此数据"+target);
                break;
            }
        }
    }
}
/*
二维数组操作
创建一个3行5列的二维数组,每个元素的取值范围是[30, 70]。
并全部把他们输出

class Z2 {
    public static void main(String[] args) {
        int[][] arr=new int[3][5];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                Random random=new Random();
                arr[i][j]=random.nextInt(40)+30;
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
    }
}


 */
class Z2{
    public static void main(String[] args) {
        Random r = new Random();
        int[][] arr = new int[3][5];
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                arr[i][j] = r.nextInt(70-30+1)+30;
                System.out.print(arr[i][j]+" ");
            }
            System.out.println();
        }
        System.out.println(Arrays.deepToString(arr));
        System.out.println(Arrays.toString(arr));
    }
}
/*
三维数组最值
创建一个3层3行5列的三维数组,每个元素是[10, 80]之间的随机数,找出数组中的最大值,
以及最大值元素的下标。

 class Z3 {
    public static void main(String[] args) {
        int[][][] arr=new int[3][3][5];
        int max=0;
        String a="";
        int b=100;
        int c=100;
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                for (int k = 0; k < arr[i][j].length; k++) {
                    Random random=new Random();
                    arr[i][j][k]=random.nextInt(70)+10;
                    if(max<arr[i][j][k]){
                        max=arr[i][j][k];
                        a+=i+",";
                        b+=j+",";
                        c+=k+",";
                    }
                }
            }
        }
        System.out.println(max);
        System.out.println(a+" "+b+" "+c);
    }
}
 */
class Z3{
    public static void main(String[] args) {
        Random r = new Random();
        int[][][] arr = new int[3][3][5];
        int max = 0;
        //{3,3,4,4,5,5}
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                for (int k = 0; k < arr[i][j].length; k++) {
                    arr[i][j][k] = r.nextInt(71)+10;
                    if(arr[i][j][k]>max){
                        max = arr[i][j][k];
                    }
                }
            }
        }
        System.out.println(Arrays.deepToString(arr));
        //寻找最大值下标
        String maxPosStr = "";
        for (int i = 0; i < arr.length; i++) {
            for (int j = 0; j < arr[i].length; j++) {
                for (int k = 0; k < arr[i][j].length; k++) {
                    if(arr[i][j][k]==max){
                        maxPosStr += "("+i+","+j+","+k+")";
                    }
                }
            }
        }
        System.out.println("max = " + max);
        System.out.println("maxPosStr = " + maxPosStr);
    }
}